package com.rc.web.controller;

import com.mybatisflex.core.paginate.Page;
import com.rc.common.annotate.WithoutTenant;
import com.rc.pojo.dto.activity.ActivityAddDTO;
import com.rc.pojo.dto.activity.ActivityPageQuery;
import com.rc.pojo.dto.activity.UpdateActivityDTO;
import com.rc.pojo.vo.activity.ActivityDetailVO;
import com.rc.pojo.vo.activity.ActivityListVO;
import com.rc.pojo.vo.activity.ActivityVO;
import com.rc.pojo.vo.activity.PageActivityVO;
import com.rc.web.service.ActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;
/**
 * 活动表 控制层。
 *
 * @author sym
 * @since 2024-05-26
 */
@RestController
@RequestMapping("/activity")
@Api(tags = "活动")
@RequiredArgsConstructor
@Validated
public class ActivityController {
    private final ActivityService activityService;

    @PostMapping
    @ApiOperation("新增")
    public void add(@RequestBody @Validated ActivityAddDTO dto) {
        activityService.add(dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public void deleteOneById(@PathVariable Long id) {
        activityService.deleteOneById(id);
    }

    @PutMapping
    @ApiOperation("修改")
    public void updateOneById(@RequestBody @Validated UpdateActivityDTO dto) throws InterruptedException {
        activityService.updateOneById(dto);
    }

    @GetMapping("/{id}")
    @ApiOperation("详情")
    public ActivityVO getByOneId(@PathVariable @NotNull Long id){
        return activityService.getOneById(id);
    }

    @GetMapping("/page")
    @ApiOperation("分页")
    public Page<PageActivityVO>  getPage(ActivityPageQuery dto){
        return activityService.getPage(dto);
    }

    @GetMapping("/detail/{id}")
    @ApiOperation("客户查看活动详情")
    @WithoutTenant
    public ActivityDetailVO detail(@PathVariable @NotNull Long id){
        return activityService.detail(id);
    }

    @GetMapping("/list")
    @ApiOperation("客户查看活动列表")
    @WithoutTenant
    public List<ActivityListVO> getList() {
        return activityService.getList();
    }
}
